<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" @click="save" size="mini">保存</el-button>
        <el-button @click="$emit('change','List')" size="mini">返回</el-button>
      </el-col>
    </el-row>
    <el-form ref="form" :rules="rules" :model="form" label-width="110px">
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form-item label="单据号" prop="q">
            <el-input v-model="form.q" :readonly="isReadOnly" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="设备编号" prop="q">
            <el-input v-model="form.q" :readonly="isReadOnly" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="设备名称" prop="q">
            <el-input v-model="form.q" :readonly="isReadOnly" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="制单人" prop="q">
            <el-input v-model="form.q" :readonly="isReadOnly" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form-item label="应检查日期" prop="q">
            <el-date-picker
              :readonly="isReadOnly"
              style="width: 100%;"
              v-model="form.q"
              type="date"
              placeholder="选择日期">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="检查时间" prop="q">
            <el-date-picker
              :readonly="isReadOnly"
              style="width: 100%;"
              v-model="form.q"
              type="date"
              placeholder="选择日期">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="检查周期" prop="q">
            <el-select style="width: 100%;" v-model="form.w" :readonly="isReadOnly" placeholder="请选择">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="所属资源" prop="q">
            <el-select style="width: 100%;" v-model="form.w" :readonly="isReadOnly" placeholder="请选择">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form-item label="使用单位" prop="q">
            <el-select style="width: 100%;" v-model="form.w" :readonly="isReadOnly" placeholder="请选择">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="检查单位" prop="q">
            <el-select style="width: 100%;" v-model="form.w" :readonly="isReadOnly" placeholder="请选择">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="检查人员" prop="q">
            <el-input v-model="form.q" :readonly="isReadOnly" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="检查类型" prop="q">
            <el-select style="width: 100%;" v-model="form.w" :readonly="isReadOnly" placeholder="请选择">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="备注" prop="q">
            <el-input v-model="form.q" :readonly="isReadOnly" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="明细" name="first"></el-tab-pane>
      <el-tab-pane label="配件" name="second"></el-tab-pane>
    </el-tabs>
    <template v-if="activeName==='first'">
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button @click="handleAdd" size="mini">新增</el-button>
          <el-button @click="handleDelete" size="mini">删除</el-button>
          <el-button @click="citation" size="mini">引单</el-button>
        </el-col>
      </el-row>
      <el-table :data="listDetail1" @selection-change="handleSelectionChange1">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="检查项目" prop="q">
          <template slot-scope="scope">
            <el-input v-model="scope.row.q" placeholder="请输入"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="检查内容" prop="w">
          <template slot-scope="scope">
            <el-input v-model="scope.row.w" placeholder="请输入"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="检查结果" prop="e">
          <template slot-scope="scope">
            <el-input v-model="scope.row.e" placeholder="请输入"></el-input>
          </template>
        </el-table-column>
      </el-table>
    </template>
    <template v-if="activeName==='second'">
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button @click="handleAdd1" size="mini">新增</el-button>        
          <el-button @click="handleDelete1" size="mini">删除</el-button>
        </el-col>
      </el-row>
      <el-table :data="listDetail2" @selection-change="handleSelectionChange2">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="行号" prop="q">
          <template slot-scope="scope">
            <el-input v-model="scope.row.q" placeholder="请输入"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="是否收费" prop="q">
          <template slot-scope="scope">
            <el-input v-model="scope.row.q" placeholder="请输入"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="材料名称" prop="q">
          <template slot-scope="scope">
            <el-input v-model="scope.row.q" placeholder="请输入"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="材料类别" prop="q">
          <template slot-scope="scope">
            <el-input v-model="scope.row.q" placeholder="请输入"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="材料规格" prop="q">
          <template slot-scope="scope">
            <el-input v-model="scope.row.q" placeholder="请输入"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="单位" prop="q">
          <template slot-scope="scope">
            <el-input v-model="scope.row.q" placeholder="请输入"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="数量" prop="q">
          <template slot-scope="scope">
            <el-input v-model="scope.row.q" placeholder="请输入"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="备注" prop="q">
          <template slot-scope="scope">
            <el-input v-model="scope.row.q" placeholder="请输入"></el-input>
          </template>
        </el-table-column>
      </el-table>
    </template>
    <!-- 引单对话框 -->
    <el-dialog title="检查内容引单" :visible.sync="open1" width="800px" append-to-body>
      <el-form :model="form1" label-width="80px" :inline="true">
        <el-form-item label="单据号">
          <el-input v-model="form1.q" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="设备名称">
          <el-input v-model="form1.q" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="检查项目">
          <el-select v-model="form1.q" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table :data="list1" @selection-change="maintenanceChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="设备名称" prop="roleName" />
        <el-table-column label="检查项目" prop="roleKey"  />
        <el-table-column label="检查内容" prop="roleSort" />
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submit">确 定</el-button>
        <el-button @click="open1=false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listRole } from "@/api/system/role";

export default {
  data() {
    return {
      // 下拉数据
      options: [],
      ids1: [],
      ids2: [],
      // tab
      activeName: 'first',
      // 是否只读
      isReadOnly: false,
      // 表单
      rules: {},
      form: {},
      // 明细配件字段
      listDetail1: [],
      listDetail2: [],
      // 引单
      open1: false,
      form1: {},
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        roleName: undefined
      }
    };
  },
  created() {
    
  },
  methods: {
    // 选择
    handleSelectionChange1() {

    },
    handleSelectionChange2() {

    },
    // tab改变
    handleClick() {
      
    },
    // 明细配件新增
    handleAdd() {
      this.listDetail1.push({ q: '',w: '',e:''})
    },
    handleAdd1() {
      this.listDetail2.push({ q: ''})
    },
    // 检查事件
    citation() { // 引单
      this.reset()
      this.getList()
      this.open1 = true
    },
    reset() {
      this.form1 = {}
    },
    handleQuery() {

    },
    resetQuery() {

    },
    maintenanceChange() {

    },
    getList() {
      listRole(this.addDateRange(this.queryParams)).then(response => {
          this.list1 = response.rows;
          this.total = response.total;
        }
      );
    },
    submit() {

    }
  }
};
</script>
